package router

import (
	"exam_go/controller"
	"exam_go/middleware"

	"github.com/gin-gonic/gin"
)

func InitRouter(r *gin.Engine) {
	// r.Use(middleware.Error)
	apiRouter := r.Group("/api")
	{
		userController := controller.UserController{}
		{
			apiRouter.POST("/user/register", userController.HandleSignup)
			apiRouter.POST("/user/login", middleware.IsNotLogin, userController.HandleLogin)
			apiRouter.DELETE("/user/logout", middleware.IsLogin, userController.HandleLogout)
			apiRouter.GET("/user/getItems", middleware.IsLogin, userController.HandleGetGoodLists)
			apiRouter.GET("/user/addCart", middleware.IsLogin, userController.HandleAddCart)
			apiRouter.GET("/user/addOrder", middleware.IsLogin, userController.HandleOrderGood)
			apiRouter.GET("/user/getItemInfo", middleware.IsLogin, userController.HandleGetGoodInfo)
			apiRouter.GET("/user/buy", middleware.IsLogin, userController.HandleBuy)
			apiRouter.POST("/user/comment", middleware.IsLogin, userController.HandleComment)
			apiRouter.DELETE("/user/deleteOrder", middleware.IsLogin, userController.HandleDeleteOrder)
			apiRouter.GET("/user/getOrders", middleware.IsLogin, userController.HandleGetOrderInfo)
			apiRouter.GET("/user/getCart", middleware.IsLogin, userController.HandleGetCartInfo)
			apiRouter.GET("/user/getSelfInfo", middleware.IsLogin, userController.HandleGetUserInfo)
			apiRouter.GET("/user/getServiceTime", middleware.IsLogin, userController.HandleGetServiceTimes)
			apiRouter.GET("/user/orderService", middleware.IsLogin, userController.HandleOrderService)
			apiRouter.POST("/user/editUserInfo", middleware.IsLogin, userController.HandleEditSelfInfo)
			apiRouter.DELETE("/user/deleteCart", middleware.IsLogin, userController.HandleDeleteCart)
			apiRouter.GET("/user/userRefund", middleware.IsLogin, userController.HandleRefund)
			apiRouter.POST("/user/userComment", middleware.IsLogin, userController.HandleUserComment)
			apiRouter.POST("/user/editPasswd", middleware.IsLogin, userController.HandleEditPasswd)
			apiRouter.GET("/user/getRest", middleware.IsLogin, userController.HandleGetRest)
		}
		AdminController := controller.AdminController{}
		{
			apiRouter.POST("admin/addItem", middleware.IsAdmin, AdminController.AddItems)
			apiRouter.POST("admin/addService", middleware.IsAdmin, AdminController.AddService)
			apiRouter.DELETE("admin/deleteItem", middleware.IsAdmin, AdminController.DeleteGoods)
			apiRouter.GET("admin/getGoods", middleware.IsAdmin, AdminController.GetGoods)
			apiRouter.DELETE("admin/deleteService", middleware.IsAdmin, AdminController.DeleteGoods)
			apiRouter.POST("admin/editItem", middleware.IsAdmin, AdminController.EditItem)
			apiRouter.POST("admin/addServiceTime", middleware.IsAdmin, AdminController.AddServiceTime)
			apiRouter.POST("admin/editService", middleware.IsAdmin, AdminController.EditService)
			apiRouter.POST("admin/getUsers", middleware.IsAdmin, AdminController.QueryUser)
			apiRouter.GET("admin/sale-item-list", middleware.IsAdmin, AdminController.HandleGetItemTimeRange)
			apiRouter.GET("admin/sale-service-list", middleware.IsAdmin, AdminController.HandleGetServiceTimeRange)
			apiRouter.GET("admin/get-total-revenue", middleware.IsAdmin, AdminController.HandleGetTotalRevenue)
			apiRouter.GET("admin/get-total-order", middleware.IsAdmin, AdminController.HandleGetTotalOrders)
			apiRouter.GET("/admin/get-total-user", middleware.IsAdmin, AdminController.HandleGetTotalUsers)
			apiRouter.GET("/admin/get-total-refund", middleware.IsAdmin, AdminController.HandleGetTotalRefunds)
			apiRouter.GET("/admin/get-total-type-goods", middleware.IsAdmin, AdminController.HandleGetSoldQuantity)
			apiRouter.GET("/admin/getItemStatus", middleware.IsAdmin, AdminController.GetItemStatus)
			apiRouter.GET("/admin/getServiceInfo", middleware.IsAdmin, AdminController.GetServiceInfo)
			apiRouter.GET("/admin/getOrderInfo", middleware.IsAdmin, AdminController.GetOrderInfo)
			apiRouter.GET("/admin/getAllInfo", middleware.IsAdmin, AdminController.GetAllInfoByName)
			apiRouter.GET("/admin/getAllItem", middleware.IsAdmin, AdminController.GetAllItem)
			apiRouter.GET("/admin/getAllService", middleware.IsAdmin, AdminController.GetAllService)
			apiRouter.GET("/admin/get-total-report", middleware.IsAdmin, AdminController.GetTotalReport)
			apiRouter.POST("/admin/editUsers", middleware.IsAdmin, AdminController.EditUsers)
			apiRouter.POST("/admin/editOrder", middleware.IsAdmin, AdminController.EditOrder)
		}
	}
}
